<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<div class="bjui-pageHeader" style="background-color:#fefefe; border-bottom:none;">
    <form data-toggle="ajaxsearch"
          data-options="{searchDatagrid:$.CurrentNavtab.find('#loanIngTable')}">
        <fieldset>
            <legend style="font-weight:normal;">搜索：</legend>

            <div style="margin:0; padding:1px 15px 15px;">

                <label class="row-label">&nbsp;标的编号：</label>
                <input type="text" name="loanNumber" class="form-control" size="14" title="标的编号">
                <label class="row-label">&nbsp;时间查询：</label>
                <input type="text" name="from" data-toggle="datepicker" data-nobtn="true" size="11">
                -
                <input type="text" name="to" data-toggle="datepicker" data-nobtn="true" size="11">

                <label class="row-label">&nbsp;标的状态：</label>
                <select name="loanStatus" title="标的状态" data-toggle="selectpicker" data-width="110">
                    <option value="">全部</option>
                    <c:forEach items="${applicationScope.loanStatusMap}" var="loanStatus">
                        <option value="${loanStatus.key}">${loanStatus.value}</option>
                    </c:forEach>
                </select>

                <label class="row-label"></label>
                <div class="btn-group">
                    <button type="submit" class="btn-green" data-icon="search">搜索</button>
                    <button type="reset" class="btn-orange" data-icon="times">重置</button>
                </div>

            </div>
        </fieldset>
    </form>
</div>
<div class="bjui-pageContent">
    <table id="loanIngTable" class="table table-bordered">
    </table>
</div>

<script type="text/javascript" src="${pageContext.request.contextPath}/js/toolDate.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/loan/loanDisplay.js"></script>
<script type="text/javascript">
    var loanIngTable;
    $(function () {
        loanIngTable = $("#loanIngTable").datagrid({
            height: '100%',
            width: '100%',
            fullGrid : true,
            showToolbar: false,
            showTfoot : true,
            filterThead: false,
            dataUrl: '/admin/capital/ing?_=' + new Date().getTime(),
            local: "remote",
            inlineEditMult: false,
            delConfirm: true,
            columns: [
                {
                    name: 'fullName',
                    label: '标名',
                    align: 'center'
                }, {
                    name: 'loanNumber',
                    label: '标号',
                    align: 'center'
                }, {
                    name: 'loanUser',
                    label: '借款人',
                    align: 'center',
                    render: loanIngShowUser
                }, {
                    name: 'loanAmountD',
                    label: '融资金额',
                    align: 'center',
                    total: 'loaning'

                }, {
                    name: 'addDate',
                    label: '融资时间',
                    align: 'center',
                    render: function (value) {
                        if (value === null || value === '') {
                            return;
                        }
                        return new Date(value).Format("yyyy年MM月dd日");
                    }
                }, {
                    name: 'beginRepayDate',
                    label: '放款时间',
                    align: 'center',
                    render: function (value) {
                        if (value === null || value === '') {
                            return;
                        }
                        return new Date(value).Format("yyyy年MM月dd日");
                    }
                }
            ],
            paging: {pageSize: 20, pageIndex: 1},
            linenumberAll: true,
            toolbarCustom: function () {
                return '<button type="button" class="btn btn-green" onclick="loanIngExportLoan();" data-icon="sign-out"><i class="fa fa-sign-out"></i> 导出</button>';
            }
        });
    });

    function loanIngShowUser(value, data) {
        return '<a href="javascript:;" onclick="loanIngopenDialog(\'' + data.loanUserId + "','" + data.loanUser + '\')">' + data.loanUser + '</a>';
    }

    function loanIngExportLoan() {
        var dates = $(loanIngTable).data('selectedDatas');

        if (dates && dates.length !== 0) {
            var ids = [];
            dates.forEach(function (e) {
                ids.push(e.id);
            });
            BJUI.ajax('ajaxdownload', {
                url: '/admin/capital/exportLoan',
                data: {ids: ids.join(",")}
            });
        } else
            BJUI.alertmsg('info', BJUI.getRegional('datagrid.selectMsg'))
    }

    function loanIngloanInfo(loanId) {
        BJUI.dialog({
            id: 'loanInfo' + loanId,
            url: '/admin/loan/loan/info?loanId=' + loanId,
            title: loanId + '标的详情',
            width: 1200,
            height: 1200 * 0.618
        })
    }

    function loanIngopenDialog(id, userName) {
        BJUI.dialog({
            id: 'userInfo_' + id,
            url: '/admin/user/userInfo?id=' + id,
            title: '' + userName + '用户信息',
            width: 1200,
            height: 1200 * 0.618
        });
    }
</script>